import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import createPersistedState from "vuex-persistedstate"
import { ajax } from './../api/index';

export default new Vuex.Store({
  plugins: [
    createPersistedState()
  ],
  state: {
    cartNum: 9,
    userInfo: null,
    city: null,
    cityList: [],
    allCinemas:[],
  },
  mutations: {
    changeUserInfo(state, payload) {
      state.userInfo = payload
    },
    changeCity(state, payload) {
      state.city = payload
    },
    changeCityList(state, payload) {
      state.cityList = payload
    },
    changeAllCinemas(state,payload){
      state.allCinemas = payload; 
    }
  },
  getters: {
    hotcity(state) {
      return state.cityList.filter(item => item.isHot == 1)
    }
  },
  actions: {
    async getCinemasAsync({commit},cityId){
      let {data} = await  ajax.getMZdata({
            cityId,
        },{
            'X-Host': 'mall.film-ticket.cinema.list'
        })
        commit('changeAllCinemas',data.cinemas)
    }
  },
  modules: {
  }
})
